package com.quanyan.place.web;

import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.place.entity.TbBizPlaceEmployee;
import com.quanyan.place.entity.apireq.ReqEmployeeInfo;
import com.quanyan.place.entity.apiresp.RespCommerceEmployee;
import com.quanyan.place.entity.vo.EmployeeFormDataVo;
import com.quanyan.place.entity.vo.PlaceInfo;
import com.quanyan.place.entity.vo.ReqPlaceSearch;
import com.quanyan.place.wrapper.CommerceEmployeeWrapper;
import com.quanyan.place.wrapper.PlaceWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by yangyun on 16-7-6.
 */
@RestController
@RequestMapping("/admin/api/place/employee")
public class CommerceEmployeeController {

    @Autowired
    CommerceEmployeeWrapper employeeWrapper;

    @Autowired
    PlaceWrapper placeWrapper;

    /**
     *  查询商务列表
     * @param reqEmployeeInfo
     * @return
     */
    @RequestMapping(value="/getEmployeeList",method = RequestMethod.POST)
    public APIResponse<?> getEmployeeList(@RequestBody ReqEmployeeInfo reqEmployeeInfo){
        PageObj<List<RespCommerceEmployee>> result=employeeWrapper.getEmployeeInfoList(reqEmployeeInfo);
        return APIResponse.returnSuccess(result);
    }

    /**
     *  商务（我的私海）列表
     * @param reqPlaceSearch
     * @return
     */
    @RequestMapping(value="/myPlaceList",method = RequestMethod.POST)
    public APIResponse<?> myPlaceList(@RequestBody ReqPlaceSearch reqPlaceSearch){
        PageObj<List<PlaceInfo>> result=placeWrapper.getCommercePlaceList(reqPlaceSearch);
        return APIResponse.returnSuccess(result);
    }


    /**
     * 新增（修改）商务员工
     * @param employeeFormDataVo
     * @return
     */
    @RequestMapping(value="/saveOrUpdateEmployee",method = RequestMethod.POST)
    public APIResponse<?> saveOrUpdateEmployee(@RequestBody EmployeeFormDataVo employeeFormDataVo){
        APIResponse apiResponse=employeeWrapper.saveOrUpdateEmployee(employeeFormDataVo);
        return apiResponse;
    }

    /*
 更改下属
     */
    @RequestMapping(value="/updateEmployeeById",method=RequestMethod.POST)
    public APIResponse<?>updateEmployeeById(@RequestBody EmployeeFormDataVo employeeFormDataVo){
        APIResponse apiResponse=employeeWrapper.updateEmployeeById(employeeFormDataVo);
        return apiResponse;
    }


    /**
     * 根据uid查询商务信息
     * @param uid
     * @return
     */
    @RequestMapping(value="/getEmployeeByUid",method = RequestMethod.GET)
    public APIResponse<?>getEmployeeByUid(@RequestParam(value = "uid", required = false)Integer uid){
        APIResponse result= employeeWrapper.getEmployeeByUid(uid);
        return result;
    }


    /**
     * 根据id查询商务信息
     * @param id
     * @return
     */
    @RequestMapping(value="/getEmployeeById",method = RequestMethod.GET)
    public APIResponse<?> getEmployeeById(@RequestParam(value = "id", required = false)Integer id){
        EmployeeFormDataVo result= employeeWrapper.getEmployeeById(id);
        return APIResponse.returnSuccess(result);
    }



    /*
     删除下属
         */
    @RequestMapping(value="/deleteEmployeeById",method = RequestMethod.GET)
    public APIResponse<?> deleteEmployeeById(@RequestParam(value = "id",required = false) Integer id){
        APIResponse apiResponse = employeeWrapper.deleteEmployeeById(id);
        return  apiResponse;
    }




    @RequestMapping(value="/getEmployeeTitleByUid",method = RequestMethod.GET)
    public APIResponse<?> getEmployeeTitleByUid(@RequestParam(value = "uid",required = false) Integer uid){
        return APIResponse.returnSuccess(employeeWrapper.getEmployeeTitleByUid(uid));
    }

}
